<template>
  <div class="comment-reply">
    <!-- 评论回复面板的顶部内容 -->
      <van-nav-bar :title="comment.reply_count > 0 ? `${comment.reply_count}条回复` : '暂无回复'">
       <van-icon name="aim" slot="left" @click="$emit('close')"/>
     </van-nav-bar>
    <!-- /评论回复面板的顶部内容 -->

    <div class="scroll-wrap">
          <!-- 当前评论项的组件 复用 -->
         <CommentItem :comment="comment">
         </CommentItem>

          <div>不想在这里写个组件分隔，好麻烦，就这样吧</div>

         <!-- 评论回复也显示 评论列表 组件 -->
         <CommentList
           :source="comment.com_id"
           :type="'c'"
           :list="commentList"
         >
         </CommentList>
    </div>

    <div class="post-wrap">
       <van-button
        class="post-btn"
        type="primary"
        size="small"
        round
        @click="isPostShow = true"
       >
       写评论
       </van-button>
    </div>

    <!-- 发布评论 -->
    <van-popup v-model="isPostShow" position="bottom">
      <!-- 需要传入文章的id和评论的id -->
      <CommentPost
       :article_comment_Id="comment.com_id"
       @post_success="onPostSuccess"
      >
      </CommentPost>
    </van-popup>
  </div>

</template>

<script>
import CommentItem from '@/views/article/comment-item.vue'
import CommentList from '@/views/article/comment-list.vue'
import CommentPost from '@/views/article/comment-post.vue'
export default {
  name: 'CommentReply',
  components: {
    CommentItem,
    CommentList,
    CommentPost
  },
  props: {
    comment: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
      isPostShow: false,
      commentList: []
    }
  },
  methods: {
    onPostSuccess (data) {
      // 关闭弹出层
      this.isPostShow = false
      // 更新 总的回复数量
      this.comment.reply_count++
      // 将刚刚发布的这条最新评论显示在 最前面
      // this.
      this.commentList.unshift(data.new_obj)
    }
  }
}

</script>

<style scoped lang="less">
.scroll-wrap {
  position: fixed;
  top: 390px;
  left: 0;
  right: 0;
  bottom: 88px;
  overflow-y: auto;
}

.post-wrap {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  border-top: 1px solid #d8d8d8;
   .post-btn {
     width: 80%;
   }
}
</style>
